package cn.edu.scau.cmi.zeyang.client;

import cn.edu.scau.cmi.zeyang.singletons.Singletons;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.layout.BorderPane;
import javafx.scene.text.Text;
import javafx.stage.Stage;

public class SingletonsClient extends Application{

	private int accout = 1;
	private Text text = new Text("暂未输入名字");
	private TextField textField = new TextField("暂未输入名字");
	@Override
	public void start(Stage primaryStage) {
		try {
			BorderPane root = new BorderPane();

			Button addButton = new Button("生成对象");
			addButton.setOnAction(e->{
				Singletons.getInstances(textField.getText());
				text.setText("输出次数:"+accout++ +","+Singletons.getInstances(textField.getText()).getName());
			});

			root.setCenter(text);
			root.setBottom(textField);
			root.setTop(addButton);

			Scene scene = new Scene(root,400,400);
			primaryStage.setTitle("实验二：单例模式");
			primaryStage.setScene(scene);
			primaryStage.show();
		} catch(Exception e) {
			e.printStackTrace();
		}
	}

	public static void main(String[] args) {
		launch(args);
	}
}

